package com.livi.tools.cas_general_backend.config.cas;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.livi.tools.cas_general_backend.entity.response.Res;
import com.livi.tools.cas_general_backend.entity.response.ResStatusEnum;
import org.jasig.cas.client.authentication.AuthenticationRedirectStrategy;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class CustomAuthenticationRedirectStrategy implements AuthenticationRedirectStrategy {

    @Override
    public void redirect(HttpServletRequest request, HttpServletResponse response,
                         String potentialRedirectUrl) throws IOException {
        Res res = Res.fail(ResStatusEnum.auth_fail, "auth fail");
        try (final PrintWriter writer = response.getWriter()) {
            writer.write(new ObjectMapper().writeValueAsString(res));
            writer.flush();
        }
    }

}